package com.yanqu.road.server.cmd.activity.stronghold.cross;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.stronghold.StrongholdWarUserData;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.strongholdwar.StrongholdModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CROSS_STRONGHOLD_WILD_LIST,desc = "跨服野外据点列表返回")
public class CrossWildListCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossStrongholdStatusResp msg = StrongholdWarProto.CrossStrongholdStatusResp.parseFrom(packet.getBytes());
        StrongholdWarProto.CrossStrongholdStatusResp.Builder resp = msg.toBuilder();
        if (!msg.hasDispatchPatrons()) {
            //如果没有派遣的门客信息，检查下本地是否有派遣
            ActivityInfo activityInfo = StrongholdActivityMgr.getActivityInfo();
            StrongholdWarUserData strongholdWarData = player.getModule(StrongholdModule.class).getStrongholdWarData(activityInfo.getActivityId());
            int wildPatronsId = strongholdWarData.getWildPatronsId();
            if (wildPatronsId > 0) {
                UserPatrons patrons = player.getModule(PatronsModule.class).getUserPatrons(wildPatronsId);
                if (patrons != null) {
                    StrongholdWarProto.StrongholdDispatchPatronsTempMsg.Builder builder = StrongholdWarProto.StrongholdDispatchPatronsTempMsg.newBuilder();
                    builder.setPatronsId(wildPatronsId);
                    builder.setCurBlood(100);
                    builder.setRewardPoints(0);
                    builder.setStrongholdId(0);
                    resp.setDispatchPatrons(builder);
                }
            }
        }
        player.sendPacket(ClientProtocol.U_STRONGHOLD_WAR_WILD_DATA_REQ,resp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
